{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b0b933d2",
   "metadata": {},
   "source": [
    "----\n",
    "* 日期：2022.09.21\n",
    "* 课程：python\n",
    "* 记录人：zhanghao\n",
    "_____"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2571f5e1",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    "\n",
    "> 1. 数值（number）\n",
    ">> 1. 定义\n",
    ">> 2. 方法\n",
    "> 2. 字符串（string）\n",
    ">> 1. 定义\n",
    ">> 2. 方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6a68e11",
   "metadata": {},
   "source": [
    "## 1.数值\n",
    "\n",
    "> 1. 对数值进行分类\n",
    ">> 1. 数值（int)\n",
    ">> 2. 浮点型（float）\n",
    ">> 3. 复数（complex）\n",
    ">> 4. 对数值的运算法则"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "80d33715",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# 整数\n",
    "a = 99\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6c2178e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "# 浮点型\n",
    "b = 99.9\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "056125c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "198.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "c = a + b\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "6065d4d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "# 复数(虚数)\n",
    "d = 2 + 3j\n",
    "print(d,type(d))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a07fbb8",
   "metadata": {},
   "source": [
    "## 字符串（str)\n",
    "> 1. 定义\n",
    "> 2. 方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "df490775",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "de693625",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can't multiply sequence by non-int of type 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [11]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m a \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m19\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m      2\u001b[0m b \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m22\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m----> 3\u001b[0m \u001b[43ma\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mb\u001b[49m\n",
      "\u001b[1;31mTypeError\u001b[0m: can't multiply sequence by non-int of type 'str'"
     ]
    }
   ],
   "source": [
    "a = \"19\"\n",
    "b = \"22\"\n",
    "a * b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "49a8004d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18 18\n",
      "<class 'int'> <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "a = 18\n",
    "b = \"18\"\n",
    "print(a,b)\n",
    "print(type(a),type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "44a42d2f",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (1964392688.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [14]\u001b[1;36m\u001b[0m\n\u001b[1;33m    \"doesn\"t\"\u001b[0m\n\u001b[1;37m           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "\"doesn\"t\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9e9b8cb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方案1\n",
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "229e784e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 解决方案2 \\后面的内容是“符号”，用于转义   \\会自动消失\n",
    "'doesn\\'t'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "49170321",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOL while scanning string literal (3827401179.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [19]\u001b[1;36m\u001b[0m\n\u001b[1;33m    \"Hello\u001b[0m\n\u001b[1;37m          ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
     ]
    }
   ],
   "source": [
    "\"Hello\n",
    "world\n",
    "\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "beb996bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 三个引号，可以包含任何文本\n",
    "# 作用：\n",
    "# 1.保持原数据的结构，包含符号，换行等，\n",
    "# 2. 可以用来做代码注释，\n",
    "NFU_招投标_HTML = \"\"\"\n",
    "<ul class=\"tzgg-div\" style=\"display: block;\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li class=\"tzgg-nr\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-time\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i>›</i>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>09-13</span>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t</a>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t</p>\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-p\">\n",
    "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">            广州南方学院智能供应链实验室建设项目竞争性磋商公告... \n",
    "    </a>\n",
    "    \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "5a3425d7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "<ul class=\"tzgg-div\" style=\"display: block;\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<li class=\"tzgg-nr\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-time\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i>›</i>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span>09-13</span>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t</a>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t</p>\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t<p class=\"tzgg-p\">\n",
      "\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"ztb/a400b894512f4cb7a1c55a8872a2b5f5.htm\">            广州南方学院智能供应链实验室建设项目竞争性磋商公告... \n",
      "    </a>\n",
      "    \n"
     ]
    }
   ],
   "source": [
    "print(NFU_招投标_HTML)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "9834371f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "### 三个引号可做多行的注释\n",
    "\n",
    "import random\n",
    "import time\n",
    "南方学院要闻 = \"https://www.nfu.cn/xxyw/index\"\n",
    "页面后缀 = \".htm\"\n",
    "page =5\n",
    "\"\"\"\n",
    "for i in range(page):\n",
    "    print(南方学院要闻 + str(i) + 页面后缀)  #字符串拼接\n",
    "    random_num = random.randint(1,10)\n",
    "    print(\"该次停留\",random_num,\"秒\")\n",
    "    time.sleep(random_num)\n",
    "    \"\"\"\n",
    "print(\"hello world\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f99f8707",
   "metadata": {},
   "source": [
    "## 2.1字符串的运算法则"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac7b2b5d",
   "metadata": {},
   "source": [
    "> 1. 字符串的拼接\n",
    "> 2. <font color=\"red\">字符串的有序性</font>\n",
    ">> 1. 取值\n",
    ">> 2. 切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "a3be9dba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Helloworld'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串的拼接\n",
    "\"Hello\" + \"world\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "7828c834",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好Alex\n",
      "你好Marry\n"
     ]
    }
   ],
   "source": [
    "# 实践\n",
    "text = \"你好\"\n",
    "for i in [\"Alex\",\"Marry\"]:\n",
    "    result = text + i\n",
    "    print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d7c822b",
   "metadata": {},
   "source": [
    "* 取值\n",
    "> 1. 取单个值\n",
    "> 2. 切片，取多个连续的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "a2c0b4fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的有序性\n",
    "地址 = \"广州市从化区温泉大道882号广州南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "1351563f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "b151a5ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "4d5ed96c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0:1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "f516fa4f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'从化区'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[3:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "69375819",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州市从化区温泉大道882号广州南方学院'"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "ead3c4f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'从化区温泉大道882号广州南方学院'"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "32e0894c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州市'"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc600e8f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实践：请检查广州是否在 地址 里面\n",
    "# 思路： 检查 i [index]是否是 广 ，然后判断i[index+1] 下一个索引值的内容是否是州\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "7b51094a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "存在 广州 这个文本\n",
      "存在 广州 这个文本\n"
     ]
    }
   ],
   "source": [
    "# 方法1：enumerate:枚举\n",
    "for index,value in enumerate (地址):\n",
    "    if value ==\"广\":\n",
    "        if 地址[index+1] == \"州\":\n",
    "            print(\"存在 广州 这个文本\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "fef04a44",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "# 方法： in 可以查询成员变量的\n",
    "print(\"广州\" in 地址)\n",
    "print(\"Alex\" in 地址)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
